// pages/my/myInformation/myInformation.js
const ins = getApp()

Page({
  data: {
    info: {},
    today: new Date()
  },
  onLoad(options) {

  },
  onReady() {
    this.fetchInfo()
  },
  onShow() {
    
  },
  onHide() {

  },
  onUnload() {

  },
  onPullDownRefresh() {

  },
  onReachBottom() {

  },
  onShareAppMessage() {

  },
  fetchInfo() {
    wx.showLoading({title: '请稍候', mask: true})

    ins.api.requestApi('resume/detail/0', 'GET', {}, {
      complete: () => {
        wx.hideLoading()
      },
      success: (resp) => {
        if(resp.data.ret == ins.globalData.request_ret.SUCCESS) {
          this.setData({info: resp.data.data})
        }
      }
    })
  },
  getLocation() {
    wx.chooseLocation({
      success: (e) => {
        this.setData({'info.address': e.address + " " + e.name})
      },
    })
  },
  valueChange(e) {
    this.setData({
      ['info.' + e.currentTarget.dataset.field]: typeof e.detail.value == 'boolean' ? (e.detail.value ? 1 : 0) : e.detail.value
    })
  },
  submit(e) {
    wx.showLoading({title: '请稍候', mask: true})

    ins.api.requestApi('resume/update', 'POST', this.data.info, {
      complete: () => {
        wx.hideLoading()
      },
      success: (resp) => {
        if(resp.data.ret == ins.globalData.request_ret.SUCCESS) {
          wx.showToast({
            title: '保存成功',
            icon: 'success',
            complete: () => {
              setTimeout(() => {
                wx.navigateBack({delta: 1})
              }, 1500)
            }
          })
        } else {
          wx.showToast({
            title: resp.data.data != null ? resp.data.data[0] : resp.data.msg,
            icon: 'none'
          })
        }
      },
      fail: () => {
        wx.showToast({
          title: '服务器错误',
          icon: 'error'
        })
      }
    })
  },

})